fn main() {
    println!("Hello, world!");
    let a = vec![1,2,0];
    Solution::first_missing_positive(a);
    let a = vec![7,8,9,11,12];
    Solution::first_missing_positive(a);
}

struct Solution;

impl Solution {
    pub fn first_missing_positive(nums: Vec<i32>) -> i32 {
        let mut ans = 0;
        let len = nums.len();
        let mut buf = vec![0; len + 1];
        let len = len as i32;
        for num in nums {
            if num > 0 && num <= len {
                buf[num as usize - 1] = 1;
            }
        }
        for index in 0..buf.len() {
            if buf[index] == 0 {
                ans = index + 1;
                break;
            }
        }
        ans as i32
    }
}
